<!--#Include File="../conn.asp" -->
<!--#Include File="comm/inc.asp" -->
<%
'====================================================================
'= Team Elite - Elite Article System
'= Copyright (c) 2005 - 2006 Eason Chan All Rights Reserved.
'=-------------------------------------------------------------------
'= 版权协议：
'=	GPL (The GNU GENERAL PUBLIC LICENSE Version 2, June 1991)
'=-------------------------------------------------------------------
'= 文件名称：/Manager/Admin_Vote.asp
'= 摘    要：后台-投票管理文件
'=-------------------------------------------------------------------
'= 最后更新：eason007
'= 最后日期：2005-12-21
'====================================================================

Call EA_Manager.Chk_IsMaster

If Not EA_Manager.Chk_Power(Admin_Power,"04") Then 
	ErrMsg=str_Comm_NotAccess
	Call EA_Manager.Error(1)
End If

Dim Atcion
Atcion=Request.QueryString ("atcion")

Select Case LCase(Atcion)
Case "add"
	Call Add
Case "save"
	Call Save
Case "del"
	Call Del
Case "lock"
	Call Locker
Case "unlock"
	Call UnLocker
Case Else
	Call Main
End Select
Call EA_Pub.Close_Obj
Set EA_Pub=Nothing

Sub Main
	Dim Count,PageCount,Page,OutStr,i,TopicList
	Dim FieldName(1),FieldValue(1)
	Dim ListBlock,Temp
	
	Page=EA_Pub.SafeRequest(3,"page",0,1,0)

	PageContent=Template.LoadTemplate("admin_vote_list.htm")

	Template.SetVariable "Language_Comm_ListEmpty",str_Comm_ListEmpty,PageContent
	Template.SetVariable "Language_Comm_Bar_Operation",str_Comm_Bar_Operation,PageContent
	Template.SetVariable "Language_Comm_Edit_Operation",str_Comm_Edit_Operation,PageContent
	Template.SetVariable "Language_Comm_Alert_Del_Operation",str_Comm_Alert_Del_Operation,PageContent
	Template.SetVariable "Language_Comm_Del_Operation",str_Comm_Del_Operation,PageContent
	Template.SetVariable "Language_Comm_Alert_Enabled",str_Comm_Alert_Enabled,PageContent
	Template.SetVariable "Language_Comm_Enabled",str_Comm_Enabled,PageContent
	Template.SetVariable "Language_Comm_Alert_Disabled",str_Comm_Alert_Disabled,PageContent
	Template.SetVariable "Language_Comm_Disabled",str_Comm_Disabled,PageContent

	Template.SetVariable "Language_OperationNotice",str_OperationNotice,PageContent
	Template.SetVariable "Language_Vote_Help",str_Placard_Help,PageContent

	Template.SetVariable "Language_Vote_VoteList",str_Vote_VoteList,PageContent
	Template.SetVariable "Language_Vote_AddVote",str_Vote_AddVote,PageContent
	Template.SetVariable "Language_Vote_Title",str_Vote_Title,PageContent
	Template.SetVariable "Language_Vote_VotedTotal",str_Vote_VotedTotal,PageContent
	Template.SetVariable "Language_Vote_Type",str_Vote_Type,PageContent
	Template.SetVariable "Language_Vote_State",str_Vote_State,PageContent


	ListBlock=Template.GetBlock("list",PageContent)

	Count=EA_M_DBO.Get_Vote_Stat()(0,0)
	If Count>0 Then 
		Template.SetVariable "ListTempty","none",PageContent

		TopicList=EA_M_DBO.Get_Vote_List(Page,15)
	
	    For i=0 To Ubound(TopicList,2)
			Temp=ListBlock

			Template.SetVariable "VoteID",TopicList(0,i),Temp
			Template.SetVariable "VoteTitle",TopicList(1,i),Temp
			Template.SetVariable "VotedTotal",TopicList(2,i),Temp
			Template.SetVariable "VoteType",TopicList(3,i),Temp
			Template.SetVariable "VoteState",TopicList(4,i),Temp
			If TopicList(5,i) Then
				Template.SetVariable "DisabledVote","none",Temp
			Else
				Template.SetVariable "EnabledVote","none",Temp
			End If
			
			Template.SetBlock "list",Temp,PageContent
		Next

		Template.SetVariable "PageListNav",EA_Manager.PageList(15,Count,Page,FieldName,FieldValue),PageContent
	End If
	Template.CloseBlock "list",PageContent


	Template.BaseReplace PageContent
	Template.OutStr PageContent
End Sub

Sub Add
	Dim PostId,Temp
	Dim Title,Typer,VoteText
	PostId=EA_Pub.SafeRequest(3,"postid",0,0,0)
	
	Temp=EA_DBO.Get_Vote_Info(PostId)
	If IsArray(Temp) Then 
		Title=Temp(1,0)
		Typer=Temp(4,0)
		VoteText=Temp(2,0)
		If Temp(5,0)=0 Then 
			ErrMsg=str_Vote_CanNotEdit
			Call EA_Manager.Error(1)
		End If	
	End If

	PageContent=Template.LoadTemplate("admin_vote_option.htm")


	Template.SetVariable "Language_Comm_Save_Button",str_Comm_Save_Button,PageContent
	Template.SetVariable "Language_Comm_Reset_Button",str_Comm_Reset_Button,PageContent
	Template.SetVariable "Language_Comm_State_Pass",str_Comm_State_Pass,PageContent
	Template.SetVariable "Language_Comm_State_NoPass",str_Comm_State_NoPass,PageContent
	Template.SetVariable "Language_Comm_Reduce_Input",str_Comm_Reduce_Input,PageContent
	Template.SetVariable "Language_Comm_Zoom_Input",str_Comm_Zoom_Input,PageContent

	Template.SetVariable "Language_OperationNotice",str_OperationNotice,PageContent
	Template.SetVariable "Language_Vote_Help",str_Placard_Help,PageContent

	Template.SetVariable "Language_Vote_VoteList",str_Vote_VoteList,PageContent
	Template.SetVariable "Language_Vote_AddVote",str_Vote_AddVote,PageContent
	Template.SetVariable "Language_Vote_Input_Vote",str_Vote_Input_Vote,PageContent
	Template.SetVariable "Language_Vote_Title",str_Vote_Title,PageContent
	Template.SetVariable "Language_Vote_Content",str_Vote_Content,PageContent
	Template.SetVariable "Language_Vote_Type",str_Vote_Type,PageContent
	Template.SetVariable "Language_Vote_Type_Radio",str_Vote_Type_Radio,PageContent
	Template.SetVariable "Language_Vote_Type_Check",str_Vote_Type_Check,PageContent

	If Typer Then
		Template.SetVariable "Type_1"," checked",PageContent
	Else
		Template.SetVariable "Type_0"," checked",PageContent
	End If
	Template.SetVariable "VoteID",PostId,PageContent
	Template.SetVariable "VoteTitle",Title,PageContent
	Template.SetVariable "VoteText",Replace(VoteText,"|",chr(13)&chr(10)),PageContent


	Template.BaseReplace PageContent
	Template.OutStr PageContent

End Sub

Sub Save
	Call EA_Pub.Chk_Post
	
	Dim Title,VoteType,VoteText,VoteNum
	Dim j,i
	Dim TempStr
	Dim PostId
	
	PostId=EA_Pub.SafeRequest(3,"postid",0,0,0)
	Title=EA_Pub.SafeRequest(2,"caption",1,"",1)
	VoteType=EA_Pub.SafeRequest(2,"type",0,0,0)
	VoteText=EA_Pub.SafeRequest(2,"vote",1,"",0)
	
	If VoteType="" Or VoteText="" Then 
		ErrMsg=str_PassDataError
		Call EA_Manager.Error(1)
	End If
	
	VoteText=Split(VoteText,Chr(13)&Chr(10))
	j=0
	
	For i = 0 To UBound(VoteText)
		If Not (VoteText(i)="" Or VoteText(i)=" ") Then
			TempStr=TempStr&""&VoteText(i)&"|"
			j=j+1
		End If
	Next

	For i = 1 To j
		VoteNum=VoteNum&"0|"
	Next

	VoteNum=Left(VoteNum,Len(VoteNum)-1)
	VoteText=Left(TempStr,Len(TempStr)-1)
	
	If Rs.State=1 Then rs.Close
	If PostId<>0 Then
		Sql="Select * From [NB_Vote] Where [Id]="&PostId
		rs.Open Sql,Conn,2,2

		TempStr = Split(VoteText, "|")
		j = UBound(TempStr)

		TempStr = Split(rs("VoteNum"), "|")
		
		If j > UBound(TempStr) Then
			For i = UBound(TempStr) To j
				rs("VoteNum") = rs("VoteNum") & "|0"
			Next
		End If
	Else
		rs.Open "NB_Vote",Conn,2,2
		rs.AddNew
		rs("VoteNum")=VoteNum
	End If
		rs("Title")=Title
		rs("VoteText")=VoteText
		rs("Type")=VoteType
		rs.update
	Rs.Close:Set Rs=Nothing
	
	Call EA_Pub.Close_Obj
	Set EA_Pub=Nothing
	
	Response.Redirect "admin_vote.asp"
End Sub

Sub Del
	Call EA_Pub.Chk_Post
	
	Dim PostId
	PostId=EA_Pub.SafeRequest(3,"postid",0,0,0)
	
	EA_M_DBO.Set_Vote_Delete PostId
	
	Call EA_Pub.Close_Obj
	Set EA_Pub=Nothing
	
	Response.Redirect Request.ServerVariables("HTTP_REFERER")
End Sub

Sub Locker
	Call EA_Pub.Chk_Post
	
	Dim PostId
	PostId=EA_Pub.SafeRequest(3,"postid",0,0,0)
	
	EA_M_DBO.Set_Vote_State 1,PostId
	
	Call EA_Pub.Close_Obj
	Set EA_Pub=Nothing
	
	Response.Redirect Request.ServerVariables("HTTP_REFERER")
End Sub

Sub UnLocker
	Call EA_Pub.Chk_Post
	
	Dim PostId
	PostId=EA_Pub.SafeRequest(3,"postid",0,0,0)
	
	EA_M_DBO.Set_Vote_State 0,PostId
	
	Call EA_Pub.Close_Obj
	Set EA_Pub=Nothing
	
	Response.Redirect Request.ServerVariables("HTTP_REFERER")
End Sub
%>